package communicationMessages;

import java.util.Date;

import data.Forum;
import data.Member;
import data.MemberDataBase;
import data.SubForum;

public class AddThreadMessage extends Message {

	@Override
	public String getAnswer() {
		String[] arr = this.content.split("\n");
		String ans = "";
		if (arr.length != 4)
		{
			System.out.println("failed\nadd thread Msg wrong format");
			ans = "failed\nadd thread Msg wrong format\n";
		}
		else
		{
			String userName,subject,body,subForumId;
			userName = arr[0];
			subject = arr[1];
			body = arr[2];
			subForumId = arr[3];
			MemberDataBase tUserDataBase =MemberDataBase.getMembersDataBase();
			Member m = tUserDataBase.getMember(userName);
			if (m == null)
			{
				ans = "user dosen't exist in the system";
				return ans;
				
			}
			Forum forum = Forum.getForum();
			SubForum subForum = forum.getSubForum(Integer.valueOf(subForumId));
			if (subForum == null){
				System.out.println("subForum is null the number is " + subForumId );
				ans = "subForum is null the number is " + subForumId;
				return ans;
			}
			subForum.addThreadMsg(subject, body,m, new Date(System.currentTimeMillis()));
			ans ="addThread\nsuccess\n";
		}
		return ans;
	}

}
